﻿using DomainBase;
using RabbitMQ.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace InfrastructureBase.Data
{
    public interface IRabbitmqConnection : IDisposable
    {
        bool IsConnected { get; }

        bool TryConnect();

        /// <summary>
        /// 创建通道
        /// </summary>
        /// <returns></returns>
        IModel CreateModel();

        /// <summary>
        /// 获取当前连接
        /// </summary>
        /// <returns></returns>
        IConnection GetConnection();

        /// <summary>
        /// 发布事件
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        void Publish<T>(T model) where T : class;


        void Publish(string message, string exChangeName);


        Task PublishAsync<T>(T model) where T:class;


        void Subscribe(string exChangeName, Action<string> callback);


        Task<T> SubscribeAsync<T>(string exChangeName) where T : class;

    }

}